<?php

class AppController extends Controller{

/**
 * for install controller :
 * no Acl component
 * no uses
 * and model access (e.g, loadModel('Model'))
 * */ 
 
 
	var $view = 'Theme';
	
	//if a beforeFilter define in controller, this one is not checked
	function beforeFilter() {
		
		if($this->params['controller'] == 'install'){
			return true;
		}
	
		if (isset($this->params[CAKE_ADMIN])){			
			$this->checkAdmin();
			$this->layout = 'admin';
		}else{
			//not admin, not install : default pages
			$this->page_header();
			$this->menu();
		}
		
	}
	
	function menu(){
		loadModel('Category');
		$this->Category = new Category();
		//TODO: pages_count updated only if is online 
		
		//recursive 0 : only category table
		$this->set('categories', $this->Category->findAll('`pages_count` > \'0\'',null, 'position ASC', null, null, 0));
	}
	
	function page_header(){
		$config['Settings'] = Configure::read('Settings');
		$this->theme = $config['Settings']['theme'];
		
		$pageHeader = null;
		foreach($config['Settings']['meta'] as $name => $content){
			$pageHeader .= '<meta name="'.$name.'" content="'.$content.'"/>';
		}
		//<meta name="Date" content="{DATE}" /> //last modified doc date : timestamp
		//<meta http-equiv="Content-Language" content="{LANG}" />
		
		$this->set('pageHeader', $pageHeader);
		$this->set('mainTitle', $config['Settings']['mainTitle']);
		$this->set('subTitle', $config['Settings']['subTitle']);
	}
	//check Session and admin rights
	function checkAdmin(){
		if($this->Session->check('User') == false){
			$this->Session->write('url', $this->params['url']['url']);
			$this->Session->setFlash('You\'re not logged in');
			$this->redirect('/admin/login');
		}else{
			$this->user = $this->Session->read('User');
		}
	}
	
	

}

?>
